package demo.bocweb.com.sdk.util;

import android.app.Activity;

import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.config.PictureMimeType;
import com.luck.picture.lib.entity.LocalMedia;

import java.util.List;

/**
 * 图片选择工具
 * Created by zhelun on 2018/1/31.
 */

public class PhotoPickerHelper {
    /**
     * 选取单张图片
     * 默认显示相机
     */
    public static void selectSinglePhoto(Activity activity, int requestCode, boolean isCrop) {
        PictureSelector.create(activity)
                .openGallery(PictureMimeType.ofImage())
                .selectionMode(PictureConfig.SINGLE)
                .isCamera(true)
                .isGif(false)
                .enableCrop(isCrop)
                .cropWH(800, 800)
                .forResult(requestCode);
    }

    /**
     * 选取单张图片
     *
     */
    public static void selectSinglePhoto(Activity activity, int requestCode, boolean isCrop, boolean isShowCamera) {
        PictureSelector.create(activity)
                .openGallery(PictureMimeType.ofImage())
                .selectionMode(PictureConfig.SINGLE)
                .isCamera(isShowCamera)
                .isGif(false)
                .enableCrop(isCrop)
                .cropWH(800, 800)
                .forResult(requestCode);
    }

    /**
     * 选取单张图片
     * 开发者自己设定裁剪图片的宽高比例
     */
    public static void selectSinglePhoto(Activity activity, int requestCode, boolean isCrop, boolean isShowCamera, int width, int height) {
        PictureSelector.create(activity)
                .openGallery(PictureMimeType.ofImage())
                .selectionMode(PictureConfig.SINGLE)
                .isCamera(isShowCamera)
                .isGif(false)
                .enableCrop(isCrop)
                .cropWH(width, height)
                .forResult(requestCode);
    }

    /**
     * 选取多张张图片  (不支持裁剪)
     * 默认显示相机
     */
    public static void selectMultiPhoto(Activity activity, int requestCode, int num) {
        PictureSelector.create(activity)
                .openGallery(PictureMimeType.ofImage())
                .selectionMode(PictureConfig.MULTIPLE)
                .isCamera(true)
                .isGif(false)
                .maxSelectNum(num)
                .forResult(requestCode);
    }

    /**
     * 选取多张张图片  (不支持裁剪)
     */
    public static void selectMultiPhoto(Activity activity, int requestCode, int num, boolean isShowCamera) {
        PictureSelector.create(activity)
                .openGallery(PictureMimeType.ofImage())
                .selectionMode(PictureConfig.MULTIPLE)
                .isCamera(isShowCamera)
                .isGif(false)
                .maxSelectNum(num)
                .forResult(requestCode);
    }

    /**
     * 选取多张图片（不支持剪裁）
     * 显示已选中的图片
     * List<LocalMedia> list （已选择的图片集合）
     */
    public static void selectMultiPhoto(Activity activity, int requestCode, int num, boolean isShowCamera, List<LocalMedia> list) {
        PictureSelector.create(activity)
                .openGallery(PictureMimeType.ofImage())
                .selectionMode(PictureConfig.MULTIPLE)
                .selectionMedia(list)
                .isCamera(isShowCamera)
                .isGif(false)
                .maxSelectNum(num)
                .forResult(requestCode);
    }

}
